<?php
	session_start();
	include_once('./mvc/modelo/Accesatabla.php');
	$razas 		 = new Accesatabla('razas');
	$detallecomp = new Accesatabla('detalle_compras');
	$tipo_ganado = new Accesatabla('tipos_ganados');
?>
<!DOCTYPE html>
<html lang="es">
	<head>
		<!-- Meta, title, CSS, favicons, etc. -->
		<meta charset="UTF-8" >
		<meta http-equiv="X-UA-Compatible" content="IE=edge">
		<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
		<link href="img/favicon.ico"  type="image/x-icon" rel="shortcut icon" />
		<title>Sistema de Ganado</title>
		<!-- CSS -->
		<link href="css/bootstrap.css" rel="stylesheet"/>
		<link href="css/estilo.css" rel="stylesheet"/>
		<!-- SCRIPTS -->
		<!-- HTML5 shim and Respond.js IE8 support of HTML5 elements and media queries -->
		<!--[if lt IE 9]>
		  <script src="js/html5shiv.js"></script>
		  <script src="js/respond.min.js"></script>
		<![endif]-->			
	</head>
	<body>
		<div class="container">
			<ul class="nav nav-pills">
				<li class="acti ve"><a href="./?url=inicio"><span class="glyphicon glyphicon-home"></span> Inicio</a></li>				
				<li class="dropdown">	
					<a href="#" class="dropdown-toggle" data-toggle="dropdown"><span class="glyphicon glyphicon-cog"></span> Mantenimiento <span class="caret"></span></a>
					<ul class="dropdown-menu">
						<li><a href="./?url=show_cliente_proveedor"><span class="glyphicon glyphicon-user"></span> Cliente / Proveedor</a></li>				
						<li><a href="./?url=show_insumos"><span class="glyphicon glyphicon-tint"></span> Agregar Insumos</a></li>				
						<li><a href="./?url=show_potreros"><span class="glyphicon glyphicon-tree-deciduous"></span> Agregar Potreros</a></li>				
						<li><a href="./?url=show_razas"><img src="./img/raza.png" style="width:20px;margin-left:-4px"> <span style="padding-right:3px;">Agregar Razas</span></a></li>				
					</ul>
				</li>
			</ul>
		</div>

		<?php 	include_once('./mvc/controlador/controlador.php'); new Controlador();?>

		<footer class="position">
			Copyright &copy; 2014 Jersey,Todos los derechos reservados.
		</footer>					
	</body>		
	<script src="js/jquery.js"></script>
	<script src="js/bootstrap.js"></script>
	<script src="js/overthrow/overthrow-detect.js"></script>		
	<script src="js/overthrow/overthrow-polyfill.js"></script>
	<script src="js/overthrow/overthrow-toss.js"></script>
	<script src="js/overthrow/overthrow-init.js"></script>
	
	<script>
		var contador = 2;
        function agrega_campos(){
            $("#ganado").append("<tr id='"+contador+"' ><td><select id='sexo' name='sexo[]' class='form-control' required><option value=''></option><option value='0' >Hembra</option><option value='1'>Macho</option></select></td><td><input type='text' name='color[]'  class='form-control'/></td><td><select id='raza' name='raza[]' class='form-control' required><option value=''></option><?php $r = $razas->buscardonde('ID>0 AND INACTIVO = 0'); while($r){ ?><option value=' <?php echo $razas->obtener('ID') ?>'><?php echo $razas->obtener('RAZA') ?></option>	<?php echo $r = $razas->releer(); } ?></select></td><td><select id='tipoganado' name='tipoganado[]' class='form-control' required><option value=''></option><?php $t = $tipo_ganado->buscardonde('ID>0 AND INACTIVO = 0'); while($t){ ?><option value=' <?php echo $tipo_ganado->obtener('ID') ?>'><?php echo $tipo_ganado->obtener('TIPO') ?></option><?php echo $t = $tipo_ganado->releer(); } ?></select></td><td><input type='text' name='precio_kg[]' class='form-control' id='precio["+contador+"]' placeholder='$' onKeyUp='multiplica("+contador+")' required/></td><td><input type='text' name='peso[]' class='form-control' id='peso["+contador+"]' placeholder='Kg' required onKeyUp='multiplica("+contador+")'/></td><td><input type='text' name='monto[]' class='form-control'  id='monto["+contador+"]'  placeholder='$' required readonly/></td><td><a href='#'' class='btn btn-danger btn-sm' onclick='elimina_me("+contador+")'><span class='glyphicon glyphicon-remove'></span></td></tr>");
            contador++;
        }
        function elimina_me(elemento){
            $("#"+elemento).remove();
        }
		function multiplica(cont){			
			var peso = document.getElementById('peso['+cont+']').value;
			var precio = document.getElementById('precio['+cont+']').value;

			m1 = parseFloat(peso);
			m2 = parseFloat(precio);
			r = m1*m2;
			
			var resultado = r.toFixed(2)
			
			document.getElementById('monto['+cont+']').value = resultado;
		}    
	</script>
	<script>
		$(document).ready(function(){
			  $("#buscar").click(function(){
			  $("#filtro").toggle();
			  });
		});
	</script>
	<script>
		$.expr[':'].Contains = function(x, y, z){
			return jQuery(x).text().toLowerCase().indexOf(z[3].toLowerCase())>=0;
		};
		$('#filtro').keyup(function() 
		{
			var search = $('#filtro').val();
			$('#ganados tr').show();
			if(search.length>0)
			{
				$("#ganados tr td.codigoganado").not(":Contains('"+search+"')").parent().hide();
			}
		});
	</script>
	<script type="text/javascript">
		function validate() {
			var b = 0, chk=document.getElementsByName("idganado[]")
			for(j=0;j<chk.length;j++) {
				if(chk.item(j).checked == false) {
				b++;
				}
			}
			if(b == chk.length) {
				alert("Seleccione uno o varios ganados...");
				return false;
			} 
			else {
				if(!confirm("\u00BFEst\u00E1 Seguro que desea continuar con los ganados seleccionados?")){
					return false;
				}
				else{
					return true;
				}
				
			}
		}
	</script>
</html>